package main

import (
	"fmt"
	cobra "gitee.com/li-haowei/cobra"
)

var name string
var age int

var showCmd = &cobra.Command{
	Use:   "show",
	Short: "A test demo",
	Long:  `The demo is a test application for print name and age`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(name) == 0 {
			fmt.Printf("Error: no name input\n")
			return
		} else if age == 0 {
			fmt.Printf("Error: no age input\n")
			return
		}

		fmt.Printf("My name is %s, and my age is %d\n", name, age)
	},
}

func init() {
	rootCmd.AddCommand(showCmd)
	showCmd.Flags().StringVarP(&name, "name", "n", "", "person's name")
	showCmd.Flags().IntVarP(&age, "age", "a", 0, "person's age")
}
